import java.util.Scanner;

public class MyMath {
    /*
    用非递归方法算最大公约数
     */
    private static int gcd(int m,int n) {
        //确保 m>n
        if (n > m) {
            int temp = n;
            n = m;
            m = temp;
        } else if (n == m)
            return m;

        int result;
        int r = m % n;
        while (r != 0) {
            m = n;
            n = r;
            r = m % n;
        }
        result = n;
        return result;
    }

    /*
    用递归方法算最大公约数
     */
    private static int gcd_recursive(int m,int n) {
        //确保 m>n
        if (n > m) {
            int temp = n;
            n = m;
            m = temp;
        } else if (n == m)
            return n;

        if (n == 0)
            return m;
        else
            return gcd_recursive(n, m % n);
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int m, n;
        int choise;
        System.out.println("输入两个数字，计算他们的最小公约数：");

        m = scanner.nextInt();
        n = scanner.nextInt();

        System.out.println("输入1调用递归方法计算，输入2调用非递归方法计算：");
        choise = scanner.nextInt();

        switch (choise) {
            case 1:
                System.out.println("最大公约数为： " + gcd_recursive(m, n));
                break;
            case 2:
                System.out.println("最大公约数为： " + gcd(m, n));
        }
    }
}